﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class PhoneTypeDataAccess
    {
        #region Methods
        public static PhoneType BindDataToPhoneType(DataRow row)
        {
            return CodeTableDataAccess.BindRowToCodeTable<PhoneType>(row);
        }

        public static void Create(PhoneType phoneType)
        {
            if(phoneType != null)
            {
                CodeTableDataAccess.Create<PhoneType>(StoredProcedures.USP_PHONETYPECODE_CREATE, phoneType.Description);
            }
        }

        public static void Delete(PhoneType phoneType)
        {
            Delete(phoneType.ID);
        }

        public static void Delete(Guid id)
        {
            List<Exception> exes = CodeTableDataAccess.Delete<PhoneType>(StoredProcedures.USP_PHONETYPECODE_DELETE, id);

            if (exes != null && exes.Count > 0)
            {
                throw exes[0];
            }
        }
        
        public static DataTable GetAll()
        {
            return CodeTableDataAccess.GetAll(StoredProcedures.USP_PHONETYPECODE_GETALL);
        }

        public static DataRow GetByID(Guid id)
        {
            return CodeTableDataAccess.GetByID(StoredProcedures.USP_PHONETYPECODE_GETBYID, id);
        }

        public static void Update(PhoneType phoneType)
        {
            if(phoneType != null)
            {
                CodeTableDataAccess.Update<PhoneType>(StoredProcedures.USP_PHONETYPECODE_UPDATE, phoneType.ID, phoneType.Description);
            }
        }
        #endregion
    }
}